<?php
/**
 * PHP Class
 *
 * LICENSE
 *
 * Processing: Component Controller
 *
 * @category   	Gnn Cms
 * @package    	Gnn Component
 * @copyright  	Copyright vinanewstar.vn@gmail.com
 * @author		GiangNam (vinanewstar.vn@gmail.com)
 * @license    	GNU General Public License Version 2 or later (the "GPL")
 * @version     v1.0 Jun 10, 2013 || 10:42:58 AM
 */
class Zendvn_Component_Controller {
	public $gcRenderView = true;
	public $gcAction;
	public $gcView;
	public $gcRequestParams;
	/**
	 * 
	 * @param Controller $controller
	 * @param String $activity
	 */
	public function __construct(IndexController &$controller,$activity = 'indexActivity'){
		$this->gcAction 		= $controller;
		$this->gcView 			= $controller->view;
		$this->gcRequestParams 	= $controller->gcRequestParams;
		
		$this->init();
		$activity  = $this->gcAction->gcComponentHelper->getActivityMethodName();
		$this->$activity();
		$this->postDispath();
		if($this->gcRenderView != false) $this->loadView();
		
	}
	public function init(){

	}
	public function postDispath(){
	}
	public function loadView(){
		require $this->gcAction->gcComponent->gcComponentPath.DS.'views'.DS.$this->gcAction->gcComponentHelper->gcControllerName.DS.$this->gcAction->gcComponentHelper->gcactivityName.'.php';
	}
	public function setNoLayout(){
		$this->gcAction->gcLoadLayout = false;
	}
	public function setNoView(){
		$this->gcRenderView   = false;
	}
	public function getTemplateUrl(){
		return $this->gcAction->gcTemplate->templateUrl;
	}
	
	public function isPost(){
		
		return $this->gcAction->isPost();
	}
	
	public function isSetParam($string){
		return isset($this->gcRequestParams[$string]);
	}
	
	public function setParam($key,$val){
		$this->gcRequestParams[$key] = $val;
	}
	public function getParam($key,$defaultValifNull = ""){
		if($this->isSetParam($key)) return $this->gcRequestParams[$key];
		return $defaultValifNull;
	}
	/**
	 * 
	 * @param String $string : string cần dịch
	 * 
	 */
	public function translate($string){
		return $this->gcView->translate($string);
	}
}